
import time

import selenium
from selenium.webdriver import chrome
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
ui='http://106.52.182.140/fanwe/'#进入方唯
dr=selenium.webdriver.Chrome()
dr.get(url=ui)#使用GET请求
dr.maximize_window()#浏览器最大化窗口
dr.implicitly_wait(15)#设置隐式等待
dr.find_element(By.ID,"login-email-address").send_keys("小可爱")#输入账号
dr.find_element(By.ID,"login-password").send_keys("a12345")#输入密码
dr.find_element(By.ID,"Iajax-login-submit").click()#点击登录
# time.sleep(2)#等待2秒
xp="//*[@id='fanwe_msg_box']/table/tbody/tr/td[2]/div[3]/input[2]"#提取取消的xpath
dr.find_element(By.XPATH,xp).click()#点击取消
time.sleep(1)#等待一秒
dk=dr.find_element(By.XPATH,"/html/body/div[1]/div[2]/div/ul/li[7]/a")
# 修改个人信息并保存-回退页面至首页，并刷新页面
dr.find_element(By.XPATH,'//*[@class="user_info_d"]/a[2]').click()
dr.refresh()#刷新浏览器页面
dr.find_element(By.ID,"edit-account").click()#点击编辑个人信息

#滚轮操作
dr.execute_script('window.scrollTo(0,500)')
time.sleep(3)
#修改省份select的属性将隐藏修改为可见
xg = 'document.querySelectorAll("select")[1].style.display="block";'
dr.execute_script(xg)
time.sleep(2)

sf=dr.find_element(By.XPATH, "/html/body/div[2]/div[3]/div[2]/form/table/tbody/tr[2]/td[2]/div[15]/div[8]/span/select[1]")
s=Select(sf)
s.select_by_index(5)#选择广东
time.sleep(2)

#修改城市select属性，将隐藏修改为可见
sf1 = 'document.querySelectorAll("select")[2].style.display="block";'
dr.execute_script("document.querySelectorAll('select')[2].style.display='block'")
time.sleep(2)
#通过select选择下拉框中的元素
g= dr.find_element(By.XPATH,"/html/body/div[2]/div[3]/div[2]/form/table/tbody/tr[2]/td[2]/div[15]/div[8]/span/select[2]")
s = Select(g)
s.select_by_index(1)#选择深圳
time.sleep(2)

dr.find_element(By.ID,"settings-submit").click()#点击保存

dr.quit()